package aqs;

import java.util.LinkedHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.IntStream;

public class test {
    public static volatile int sum = 0;
    public static final Object lock = new Object();
    public static void main(String[] args) throws InterruptedException {
        MyAQSLock myAQSLock = new MyAQSLock();
        CountDownLatch countDownLatch = new CountDownLatch(1000);
        for(int i = 0; i < 1000; i++) {
            new Thread(()->{
                myAQSLock.lock();
                try {
                    sum++;
                }finally {
                    myAQSLock.unlock();
                }
                countDownLatch.countDown();
            }).start();
        }
        countDownLatch.await();
        System.out.println(sum);
    }
}
